﻿using AutoMapper;
using CustomerService;
using J.CustomerGet.Application.Command.CustomerListCommand;
using J.CustomerModel;
using MediatR;

namespace J.CustomerGet.Application.CommandHandler.CustomerListCommandHandler
{
    public class CustomerAddCommandHandler : IRequestHandler<CustomerAddCommand, int>
    {
        private readonly ICustomerListService _customerListService;
        private readonly IMapper _mapper;
        public CustomerAddCommandHandler(ICustomerListService customerListService, IMapper mapper)
        {
            _customerListService = customerListService;
            _mapper = mapper;
        }

        public async Task<int> Handle(CustomerAddCommand request, CancellationToken cancellationToken)
        {
            CustomerList model = _mapper.Map<CustomerList>(request);
            return await _customerListService.CustomerAdd(model);
        }
    }
}
